package com.project.Util;

import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;

/**
 * @author lyl
 * description:
 */
public class MFUtil {
    public static String MFTrance(MultipartFile mf, String picPath) throws IOException {
        String imgPath = mf.getOriginalFilename();
        //将文件名以时间毫秒数重新命名
        imgPath = System.currentTimeMillis() + imgPath.substring(imgPath.lastIndexOf("."));
        //将文件以二进制数据进行传输至target文件夹
        URL url = Thread.currentThread().getContextClassLoader()
                .getResources(picPath).nextElement();
        String filePath = URLDecoder.decode(url.getFile(), "utf-8");
        mf.transferTo(new File(filePath + "/" + imgPath));
        System.out.println(imgPath);
        return imgPath;
    }
}
